package com.juzi.wopu.service.impl;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com.juzi.wopu.domain.SysUser;
import com.juzi.wopu.query.SysUserQuery;
import com.juzi.wopu.service.ISysUserService;

public class SysUserServiceImpl extends BaseServiceImpl<SysUser> implements ISysUserService{

	@Override
	public void getSysUserMap(Map<Long, SysUser> map1, Map<String, SysUser> map2) {
		List<SysUser> list=BaseDao.getAll(SysUser.class);
		if(list!=null && list.size()>0){
			if(map1!=null && map2==null){
				for(SysUser s:list){
					map1.put(s.getiId(), s);
				}
			}
			else if(map1==null && map2!=null){
				for(SysUser s:list){
					map2.put(s.getsMobile(), s);
				}
			}
			else if(map1!=null && map2!=null){
				for(SysUser s:list){
					map1.put(s.getiId(), s);
					map2.put(s.getsMobile(), s);
				}
			}
		}
	}

	@SuppressWarnings("unchecked")
	@Override
	public SysUser findOne(SysUserQuery query) {
		String hql="from SysUser where 1=1";
		if (StringUtils.isNotBlank(query.getsUserNo())) {
			hql=hql+" and sUserNo='"+query.getsUserNo()+"'";
		}
		
		if (StringUtils.isNotBlank(query.getsMobile())) {
			hql=hql+" and sMobile='"+query.getsMobile()+"'";
		}
		
		if (query.getiCompany()!=null && query.getiCompany()!=-1L) {
			hql=hql+" and iCompany="+query.getiCompany();
		}
		List<SysUser> list=BaseDao.findByhql(hql);
		if(list==null || list.size()==0){
			return null;
		}else {
			return list.get(0);
		}
	}

	@Override
	public void deleteByMobile(String mobile) {
		String sql="delete from [pm].[dbo].[tSysUser] where sMobile='"+mobile+"'";
		BaseDao.executeSql(sql);
	}
}
